package com.demo2;

public class StringBuilderDemo6 {
    public static void main(String[] args) {
        //1.定义数组
        int[] arr={1,2,3};
        //2.带哦用方法把数组变成字符串
        String str = arrToString(arr);
        System.out.println(str);
    }

    public static String arrToString(int[] arr){
        StringBuilder builder = new StringBuilder();
        builder.append("[");
        for (int i = 0; i < arr.length; i++) {
            if(i==arr.length-1){
                builder.append(arr[i]);
            }else{
                builder.append(arr[i]).append(", ");
            }
        }
        builder.append("]");
        return builder.toString();
    }
}
